# -*- encoding: utf-8 -*-

# Copyright 2010 István Szentandrási
# <etude-music-player@googlegroups.com>

# This file is part of Etude.
#
# Etude is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as 
# published by the Free Software Foundation, either version 3 
# of the License, or (at your option) any later version.
#
# Etude is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Etude. If not, see <http://www.gnu.org/licenses/>.

from . import _

LYRICS_SOURCE = 'client/generic'

MAIN_PROP = 'lyrics'

class ArtWriter:

    def __init__(self, client):
        self.client = client

    def write(self, id, data):
        self.client.bindata.add(str(data), 
                cb=lambda md5_hash: self.set_hash(id, md5_hash))

    def set_hash(self, id, md5_hash):
        def _set_hash(minfo):
            if MAIN_PROP in minfo:
                self.client.bindata.remove(minfo[MAIN_PROP])
            self.client.medialib.property_set(id, MAIN_PROP, md5_hash,
                    LYRICS_SOURCE)

        self.client.medialib.get_info(id, cb=_set_hash)

